﻿using Common.Extensions;
using Common.Utility;
using Interface.Volcengine.DTO;
using Interface.Volcengine.DTO.CVProcess;
using TencentCloud.Common.Profile;
using TencentCloud.Common;
using TencentCloud.Hunyuan.V20230901.Models;
using TencentCloud.Hunyuan.V20230901;
using System.Security.Policy;

namespace Interface.TencentCloud
{
    public class TencentCloudApi
    {
        private readonly string SecretId = AppSetting.GetAppSetting("TencentCloud:SecretId");
        private readonly string SecretKey = AppSetting.GetAppSetting("TencentCloud:SecretKey");

        public TencentCloudApi()
        {
        }

        public async Task<TextToImageLiteResponse> TextToImageLite(string prompt)
        {
            try
            {
                Credential cred = new Credential
                {
                    SecretId = SecretId,
                    SecretKey = SecretKey
                };
                // 实例化一个client选项，可选的，没有特殊需求可以跳过
                ClientProfile clientProfile = new ClientProfile();
                // 实例化一个http选项，可选的，没有特殊需求可以跳过
                HttpProfile httpProfile = new HttpProfile();
                httpProfile.Endpoint = (AppSetting.GetAppSetting("TencentCloud:HunYuan:Endpoint"));
                clientProfile.HttpProfile = httpProfile;

                // 实例化要请求产品的client对象,clientProfile是可选的
                HunyuanClient client = new HunyuanClient(cred, AppSetting.GetAppSetting("TencentCloud:HunYuan:TextToImageLite:Region"), clientProfile);
                // 实例化一个请求对象,每个接口都会对应一个request对象
                TextToImageLiteRequest req = new TextToImageLiteRequest();
                req.Prompt = prompt;
                req.RspImgType = "url";
                // 返回的resp是一个TextToImageLiteResponse的实例，与请求对象对应
                return await client.TextToImageLite(req);
            }
            catch (Exception e)
            {
                LogHelper.Error($"TextToImageLite", e);
                throw new Exception(e.Message);
            }
        }
    }
}
